<template>
  <div v-show="showTable == 2" class="table-box">
    <div class="box-title">
      <p style="fontsize: 16px; fontweight: bold">
        {{ $t('conditionInformation') }}
      </p>
      <el-button
        :disabled="tableDisabled"
        type="success"
        icon="el-icon-plus"
        @click="pushCondition"
      >{{ $t("add") }}</el-button
      >
    </div>
    <el-table
      :data="checkItemConditions"
      :header-cell-style="headerCellStyle"
      border
      style="width: 100%"
      align="center"
      tooltip-effect="dark"
    >
      <el-table-column :label="$t('EnumCheckItemApply_Condition')" prop="condition" align="center">
        <template slot-scope="scope">
          <el-select
            v-model="scope.row.condition"
            :disabled="tableDisabled"
            style="width: 100%"
          >
            <el-option
              v-for="item in conditionList"
              :key="item.id"
              :label="$t(item.name)"
              :value="item.id"
            />
          </el-select>
        </template>
      </el-table-column>
      <el-table-column
        :label="$t('conditionValue')"
        prop="conditionValue"
        align="center"
      >
        <template slot-scope="scope">
          <el-input
            v-model="scope.row.conditionValue"
            :disabled="tableDisabled"
            style="width: 100%"
            placeholder="条件多个以英文逗号隔开"
          />
        </template>
      </el-table-column>
      <el-table-column
        :label="$t('conditionalDirection')"
        prop="checkMode"
        width="200"
        align="center"
      >
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.checkMode"
            :active-value="1"
            :inactive-value="0"
            :disabled="tableDisabled"
            style="display: inline-block"
            active-color="#13ce66"
            inactive-color="#ff4949"
            active-text="正向"
            inactive-text="反向"
          />
        </template>
      </el-table-column>
      <el-table-column
        v-if="showValid"
        :label="$t('iseffective')"
        prop="valid"
        align="center"
        width="100"
      >
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.valid"
            :active-value="1"
            :inactive-value="0"
            :disabled="tableDisabled"
            active-color="#13ce66"
            inactive-color="#ff4949"
          />
        </template>
      </el-table-column>
      <el-table-column :label="$t('operation')" align="center" width="100">
        <template slot-scope="scope">
          <el-button
            :disabled="tableDisabled"
            type="text"
            @click="doConditionDelete(scope.$index, checkItemConditions)"
          >{{ $t('delete') }}</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import eFormApi from '@/api/eForm/selectItemList'

export default {
  name: 'InformationTable',
  components: {},
  mixins: [],
  props: {
    checkItemConditions: {
      type: Array,
      default: () => { [] }
    },
    tableDisabled: {
      type: Boolean,
      default: false
    },
    showTable: {
      type: Number,
      default: 0
    },
    showValid: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      conditionList: [],
      headerCellStyle: Object.freeze({
        background: '#F2F6FC',
        color: '#606266'
      })
    }
  },
  computed: {},
  watch: {},
  created() {
    this.getCondition()
  },
  mounted() {},
  methods: {
    //   添加
    pushCondition() {
      this.checkItemConditions.push({})
    },
    // 获取条件下拉框
    async getCondition() {
      const res = await eFormApi.getCondition()
      this.conditionList = res.data
    },
    // 删除表单
    doConditionDelete(index, rows) {
      rows.splice(index, 1)
    }
  }
}
</script>

<style scoped lang="scss">
.table-box {
  .box-title {
    height: 30px;
    box-sizing: border-box;
    padding: 0 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 20px 0;
  }
}
</style>
